package com.cn.wanxi.IO;

import com.cn.wanxi.IOModel.CompanyIOModel;

import java.io.*;

/**
 * IO逻辑层
 * 1.写入记事本
 * 2.读取数据
 * 3.封装数据
 */
public class CompanyIO {


    public void writeNote(String path) {
        File file = new File(path);
        //判斷该路径是否存在，如果不存在则创建
//        System.out.println(file.exists());
//        if (!file.exists()) {
//    file.mkdir();//
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //字母，数字一个字节，特殊字符一个字节，enter键和汉字两个字节
        try {
//            输出流
            OutputStream outputStream = new FileOutputStream(file);
            CompanyIOModel companyIOModel = new CompanyIOModel();
            outputStream.write(companyIOModel.getLogo().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getAddress().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getPhone().getBytes());//写入电话号码
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getAd().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getNet().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getEmail().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getLinePhone().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getVersion().getBytes());
            outputStream.write("@@".getBytes());
            outputStream.write(companyIOModel.getContent().getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
